﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessModel;
using BusinessModel.EntityModel;

namespace SDZJ.ManagerView.StudentManager
{
    public partial class ScoreCodeManager : System.Web.UI.Page
    {
        #region********变量定义**************
        /// <summary>
        /// 当前页面
        /// </summary>
        public int currentPage = 1;

        /// <summary>
        /// 查询条件
        /// </summary>
        public string condition = "";
        /// <summary>
        ///日志信息实体
        /// </summary>
        LogInfo logInfo = new LogInfo();
        /// <summary>
        ///日志信息操作类
        /// </summary>
        LogHelper cLog = new LogHelper();
        #endregion***************************

        protected void Page_Load(object sender, EventArgs e)
        {
            //防止SQL注入
            AvertInjection.OnLoadCheck();
            //登录用户信息
            if (Session["currentUserID"] != null)
            {
                //currentUserID = Session["currentUserID"].ToString();
            }
            if (Session["UserName"] != null)
            {
                //currentUserName = Session["UserName"].ToString();
            }

            if (!IsPostBack)
            {
                AspNetPager.CurrentPageIndex = 1;
                getData();
            }
        }

        protected void refAddCourseCate_Click(object sender, EventArgs e)
        { 
            getData();
            
        }

        protected void refDelCourseCate_Click(object sender, EventArgs e)
        {
            //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "", "alert(" + this.selectedIndex.Value + ")", true);
            Table_ScoreCode ts = new Table_ScoreCode();
            int si = Convert.ToInt32(this.selectedIndex.Value);

            ts.SCORERECORD_ID = ((Label)scoreView.Rows[si].Cells[0].FindControl("SCORERECORD_ID")).Text;
            EntityOprHelper entityHelper = new EntityOprHelper();
            if (entityHelper.DelEntity<Table_ScoreCode>(ts))
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "", "alert('删除成功');refHandel()", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "", "alert('删除失败');refHandel()", true);
            }
        }

        private void getData()
        {
           // this.selectedIndex.Value = "-1";
            this.AspNetPager.PageChanged -= AspNetPager_PageChanged;
            EntityOprHelper entityHelper = new EntityOprHelper();
            //  List<Table_ScoreCode> scoreCode = entityHelper.GetEntityList<Table_ScoreCode>("");
            string sqlStr = "select a.Name as STUDENT,c.NAME as BRANCH_SCHOOL_NAME,b.* from EL_STUDENT a,EL_SCORERECORD b,EL_BRANCHSCHOOL c where a.studentid=b.studentid and a.BRANCH_SCHOOL_ID=c.BRANCH_SCHOOL_ID";
            List<View_ScoreCodeManager> scoreCode = entityHelper.GetEntityListBySql<View_ScoreCodeManager>(sqlStr, AspNetPager.PageSize, AspNetPager.CurrentPageIndex, AspNetPager, "t");
            // List<MaterialListInfo> newsType = entityHelper.GetEntityList<MaterialListInfo>("");
            this.scoreView.DataSource = scoreCode;
            this.scoreView.DataBind();

            currentPage = AspNetPager.CurrentPageIndex;
            if (currentPage > 1)
            {
                AspNetPager.FirstPageText = "<img src=../images/page02.gif border=0 valign=middle hspace=3>";
                AspNetPager.PrevPageText = "<img src=../images/page01.gif border=0 valign=middle hspace=3>";
            }
            else
            {
                AspNetPager.FirstPageText = "<img src=../images/page05.gif border=0 valign=middle hspace=3>";
                AspNetPager.PrevPageText = "<img src=../images/page06.gif border=0 valign=middle hspace=3>";
            }

            if (currentPage == AspNetPager.PageCount || AspNetPager.PageCount == 0)
            {
                AspNetPager.LastPageText = "<img src=../images/page08.gif border=0 valign=middle hspace=3>";
                AspNetPager.NextPageText = "<img src=../images/page07.gif border=0 valign=middle hspace=3>";
            }
            else
            {
                AspNetPager.LastPageText = "<img src=../images/page04.gif border=0 valign=middle hspace=3>";
                AspNetPager.NextPageText = "<img src=../images/page03.gif border=0 valign=middle hspace=3>";
            }
            this.AspNetPager.PageChanged += AspNetPager_PageChanged;
        }

        /// <summary>
        /// 分页控件翻页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_PageChanged(object sender, EventArgs e)
        {
            // 记录列表当前页码
            getData();
        }

        protected void scoreView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                scoreView.HeaderRow.Cells[0].Visible = false;
                e.Row.Cells[0].Visible = false;
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#f4fff7'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                e.Row.Attributes["style"] = "cursor:hand";
                e.Row.Attributes.Add("ondblclick", "alert('" + e.Row.RowIndex + "')");

                e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'}");//当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");//当鼠标移开时还原背景色
                e.Row.Attributes.Add("onclick", "selectx(this," + e.Row.RowIndex + ");");
            }
        }
    }
}